<template>
    <div>
        <div class="JudgeResearchSituation">
            <h1>科研情况</h1>
            <el-table :data="ResearchSituation" style="width: 100%" :key="researchId">
                <el-table-column prop="rank" label="名次">{{ user.rank }}</el-table-column>
                <el-table-column prop="time" label="时间">{{ user.time }}</el-table-column>
                <el-table-column prop="place" label="地点">{{ user.place }}</el-table-column>
                <el-table-column prop="prize" label="奖项">{{ user.prize }}</el-table-column>
            </el-table>
        </div>
        <div class="update">
            <el-form ref="form" :model="user" :rules="rules">
                <el-form-item v-for="(user,researchId) in userList" 
                :key="researchId"
                prop="service">
                    评分
                    <el-input class="test3" v-model="user.rsmark" placeholder="请输入分数"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="submitForm">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
  </template>

<script>
import { getRSInfo } from "@/api/login";
import { updateJRSinfo } from "@/api/login";

export default {
  name: "JudgeResearchSituation",
  data() {
    return {
      userList:[{user:1,researchId:1}],//这是测试用例
          user: {
              username:"",
              researchId: "",
              rank:"",
              time:"",
              place:"",
              prize:"",
              rsmark:""
      },
      rules: {
        service: [{ required: true, message: "请输入分数", trigger: "blur" }],
      },
    };
  },
  mounted() {
    getRSInfo().then((res) => {
      this.user.username = res.data.username;
      this.user.researchId = res.data.researchId;
      this.user.rank = res.data.date;
      this.user.time = res.data.time;
      this.user.place = res.data.place;
      this.user.prize = res.data.prize;//是data标签下的内容，在api取名时注意
    });
  },
  methods:{
    submitForm() {
      this.$refs.form.validate(valid => {
          if (valid) {
            this.loading = true
            //发起网络请求登录，如果登录成功，跳转到主页面
            //操作与login api联系
            updateJRSinfo(this.user.username,this.user.researchId,this.user.rsmark).then(res =>{
              console.log(res.data.accessToken)
              setToken(res.data.accessToken)
            }).catch(() => {
              // 上传，
              this.loading = true
            })
          }
        })
    },
    resetForm() {
    },
  }

};
</script>

<style>
.JudgeResearchSituation {
  padding: 20px;
}

.test3{
    width: 150px !important;
  }
</style>